package com.yaozheng.vocationaltraining.service.impl;

import com.yaozheng.vocationaltraining.iview.BaseView;
import com.yaozheng.vocationaltraining.iview.IBuyCalculatorView;
import com.yaozheng.vocationaltraining.iview.IQuestionsDetailView;
import com.yaozheng.vocationaltraining.service.BuyCalculatorService;
import com.yaozheng.vocationaltraining.utils.Constants;
import com.yaozheng.vocationaltraining.utils.ErrorUtils;
import com.yaozheng.vocationaltraining.utils.http.okhttp.OkHttpClientManager;

import net.sf.json.JSONObject;

import org.androidannotations.annotations.Background;
import org.androidannotations.annotations.EBean;

/**
 * Created by moon on 2017/11/12.
 */

@EBean
public class BuyCalculatorServiceImpl implements BuyCalculatorService {
    private IBuyCalculatorView iTokenBaseView;
    @Override
    public void init(IBuyCalculatorView iTokenBaseView) {
        this.iTokenBaseView = iTokenBaseView;
    }

    @Background
    @Override
    public void list() {
        try {
            OkHttpClientManager
                    .getInstance()
                    .get( Constants.ROOTURL + "/car/categories"
                            , iTokenBaseView.getToken(), new BaseView(iTokenBaseView) {
                        @Override
                        public void responseSuccess(JSONObject jsonObject) {
                            iTokenBaseView.responseSuccess(jsonObject);
                        }

                        @Override
                        public void responseError(String error) {
                            iTokenBaseView.responseError(error);
                        }
                    });
        } catch (Exception e) {
            ErrorUtils.outErrorLog(e);
            if (iTokenBaseView.isResponseResult()) {
                iTokenBaseView
                        .responseError(ErrorUtils.SERVER_CONNECTION_ERROR);
            }

        }
    }


}
